package com.chi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @PostMapping("/login")
    public String login(@RequestParam("password") String password, HttpSession session, Model model){
        if (password.equals("luchijiayou1")){
            session.setAttribute("password","luchijiayou1");
            return "redirect:/Pwd/getPwdList";
        }else {
            model.addAttribute("msg","暗号错误！");
            return "forward:/index.jsp";
        }
    }

    @GetMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("password");
        return "forward:/index.jsp";
    }
}
